﻿using System;
using System.Linq;

namespace Dpy.Math.Geometry.Geometry2D
{
    public class Circle
    {
        #region Fields

        private double radius;

        #endregion


        #region Properties

        public Vector2D Center { get; set; }

        public double Radius
        {
            get
            {
                return this.radius;
            }
            set
            {
                if (value < 0 || value.IsZero())
                {
                    throw new ArgumentException("Circle radius must be greater than zero!");
                }

                this.radius = value;
            }
        }

        public double Perimeter
        {
            get
            {
                return 2 * System.Math.PI * this.Radius;
            }
        }

        public double Area
        {
            get
            {
                return System.Math.PI * this.Radius * this.Radius;
            }
        }

        #endregion


        #region Constructors

        public Circle(Vector2D center, double radius)
        {
            this.Center = center;
            this.Radius = radius;
        }

        #endregion


        #region

        public Vector2D GetPointFromRadiusVector(Vector2D radiusVector)
        {
            if (radiusVector.TryNormalize())
            {
                return this.Center + (radiusVector * this.Radius);
            }
            else
            {
                throw new ArgumentException("Cannot pass zero vector as argument!", "fromCenterRadiusVector");
            }
        }

        #endregion


        #region Overriden methods

        public override string ToString()
        {
            string listSeparator = Dpy.Math.Utility.CurrentCulture.TextInfo.ListSeparator;

            return string.Format("({0}{1} {2})", this.Center.ToString(), listSeparator, this.Radius);
        }

        #endregion
    }
}
